package com.ruoyi.ipms_crm.controller;


import com.ruoyi.common.core.constant.RabbitMQConstants;
import com.ruoyi.common.core.rabbitmq.EmailMQSender;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.ipms_crm.dto.*;
import com.ruoyi.ipms_crm.entity.Customer;
import com.ruoyi.ipms_crm.service.CustomerService;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * 客户controller
 */

/*客户表示层*/
@RestController
@RequestMapping("/crm")
@RefreshScope    //开启支持nacos动态配置修改，默认是关闭，要开启
public class CustomerController extends BaseController {

    @Resource
    private CustomerService customerService;

    @Resource
    private EmailMQSender emailMQSender;

    /*查询当前业务员客户列表*/
    @GetMapping("/list")
    public TableDataInfo SelectCustomerListByUserId(Customer customer){
        startPage();
        List<Customer> list=customerService.SelectCustomerListByUserId(customer);
        return getDataTable(list);
    }

    /*查询客户公海列表*/
    @GetMapping("/seas/list")
    public TableDataInfo selectListByCustomerSeas(Customer customer){
        startPage();
        List<Customer> list=customerService.selectListByCustomerSeas(customer);
        return getDataTable(list);
    }

    /*
     * Description : TODO 查询客户回收站列表
     * ChangeLog : 创建 ([zhouhongcheng]);
     */
    @GetMapping("/recycle/list")
    public TableDataInfo selectRecycleCustomerList(Customer customer){
        startPage();
        List<Customer> list=customerService.selectRecycleCustomerList(customer);
        return getDataTable(list);
    }

    /*
     * Description : TODO 回收站客户返回公海
     * ChangeLog : 创建 ([zhouhongcheng]);
     */
    @GetMapping("/recycleLeave/{customerIds}")
    public AjaxResult updateCustomer(@PathVariable("customerIds") List customerIds) {
        return AjaxResult.success(customerService.updateCustomer(customerIds));
    }

    /*查询客户详情*/
    @GetMapping("/find/{customerId}")
    public AjaxResult selectCustomerById(@PathVariable("customerId") Integer customerId) {
        return AjaxResult.success(customerService.selectCustomerById(customerId));
    }

    /*新增客户*/
    @PostMapping
    public AjaxResult insertCustomer(@RequestBody Customer customer){
        return  toAjax(customerService.insertCustomer(customer));
    }


    /*修改客户详情*/
    @PutMapping
    public AjaxResult updateCustomer(@RequestBody Customer customer){
        System.out.println(customer);
        return  toAjax(customerService.updateCustomerById(customer));
    }

    /*删除客户*/
    @DeleteMapping("/{customerId}")
    public  AjaxResult deleteCustomer(@PathVariable Integer[] customerId){
        return  toAjax(customerService.deleteCustomerByIds(customerId));
    }

    /*查询客户详情DTO*/
    @GetMapping("/detailes/{customerId}")
    public AjaxResult selectCustomerDetails(@PathVariable("customerId") Integer customerId){
        return AjaxResult.success(customerService.selectCustomerDetails(customerId));
    }


    /*查询客户详情发明人DTO*/
    @GetMapping("/Inventor/{customerId}")
    public TableDataInfo selectInventorForCustomer(@PathVariable("customerId") Integer customerId){
        startPage();
        List<CustomerAndInventorDto> list=customerService.selectInventorForCustomer(customerId);
        return getDataTable(list);
    }

    /*查询客户详情申请人DTO*/
    @GetMapping("/applicant/{customerId}")
    public TableDataInfo selectApplicantForCustomer(@PathVariable("customerId") Integer customerId){
        startPage();
        List<CustomerAndApplicationDto> list=customerService.selectApplicantForCustomer(customerId);
        return getDataTable(list);
    }

    /*查询客户详情合同DTO*/
    @GetMapping("/con/{customerId}")
    public TableDataInfo selectContractForCustomer(@PathVariable("customerId") Integer customerId){
        startPage();
        List<CustomerOfContractDto> list=customerService.selectContractForCustomer(customerId);
        return getDataTable(list);
    }
    /*查询客户详情案件DTO*/
    @GetMapping("/case/{customerId}")
    public TableDataInfo selectCaseForCustomer(@PathVariable("customerId") Integer customerId){
        startPage();
        List<CustomerOfCaseDto> list=customerService.selectCaseForCustomer(customerId);
        return getDataTable(list);
    }


}
